import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm } from 'naive-ui'
import { OrgModel } from '@/api/model/org-model'

type props = {
  handleEditOrg: (row: OrgModel) => void
  fetchDelOrg: (id: number) => void
  handleEditOrgParam: (row: OrgModel) => void
}

export const useOrgProTable = ({
  handleEditOrg,
  fetchDelOrg,
  handleEditOrgParam
}: props) => {
  const columns: ProTableColumn<OrgModel>[] = [
    {
      title: '机构名称',
      key: 'orgName',
      query: {
        type: 'input'
      }
    },
    {
      title: '机构编号',
      key: 'orgCode',
      query: {
        type: 'input'
      }
    },
    {
      type: 'dict',
      title: '机构类型',
      key: 'type',
      dictCode: 'ORG_TYPE',
      query: {
        type: 'select'
      }
    },
    {
      title: '所属大洲',
      key: 'continent',
      query: {
        type: 'select'
      },
      dictCode: 'ORG_CONTINENT'
    },
    {
      title: '所属国家',
      key: 'country',
      query: {
        type: 'input'
      }
    },
    {
      title: '所属城市',
      key: 'city',
      query: {
        type: 'input'
      }
    },
    {
      title: '创建时间',
      key: 'createTime'
    },
    {
      title: '操作',
      key: 'operation',
      width: 200,
      render(row) {
        return (
          <>
            <NButton
              type="info"
              size="small"
              onClick={() => handleEditOrgParam(row)}
              quaternary
            >
              参数配置
            </NButton>
            {useHasPermi('org:edit') && (
              <NButton
                type="primary"
                size="small"
                onClick={() => handleEditOrg(row)}
                quaternary
              >
                修改
              </NButton>
            )}
            {useHasPermi('org:del') && (
              <NPopconfirm onPositiveClick={() => fetchDelOrg(row.id)}>
                {{
                  trigger: () => (
                    <NButton size="small" type="error" quaternary>
                      删除
                    </NButton>
                  ),
                  default: () => '您确定要删除？'
                }}
              </NPopconfirm>
            )}
          </>
        )
      }
    }
  ]

  return {
    columns
  }
}
